import { UITransform, view, Node, Size, color, Vec3, Color } from "cc";
import { GameManager } from "../Model/GameManager";

export class Global {

    static gameManager: GameManager = null;

    static GameNode: Node = null;
    static GameNodeTran: UITransform = null;

    static GravityCricleRenderer: boolean = false;//开启引力圈绘制
    static LinearVelocityRenderer: boolean = false;//开启速度线绘制
    static MapBlockRenderer: boolean = false;
    static TrackerDebug: boolean = false;

    /**允许地图生成天体 */
    static EnableMapSpawn: boolean = true;

    static config: { [key: string]: any } = null;

    /**摄像机的视角范围 */
    static CameraOrthoHeight: number = 360;
    static UsingFixedJoystick: boolean = false;
    static isIOSDevices: boolean = false;

    //视角缩放系数
    static get CameraOrthoScale() {
        return this.CameraOrthoHeight / this.designScreenSize.height * 2;
    }

    static get windowSize() {
        return view.getViewportRect().size
    }

    static get designScreenSize() {
        return view.getDesignResolutionSize();
    }

    private static _winScale: Size = null;
    /**设备真实缩放比例与设计屏幕缩放比例的比值 */
    static get screenAdjustScale() {
        if (this._winScale == null) {
            this._winScale = new Size();
            let designResolution = view.getDesignResolutionSize();
            let targetAspectRatio = this.screenAspectRatio;
            let designAspectRatio = designResolution.width / designResolution.height;
            let scaleW = targetAspectRatio / designAspectRatio;

            this._winScale.width = scaleW;//宽的适配前后比

            targetAspectRatio = this.windowSize.height / this.windowSize.width;
            designAspectRatio = designResolution.height / designResolution.width;
            let scaleH = targetAspectRatio / designAspectRatio;

            this._winScale.height = scaleH;//高的适配前后比
        }

        return this._winScale;
    }

    private static _adjustSize: Size = null;
    /**获取实际的屏幕大小 */
    static get screenAdjustSize() {
        if (this._adjustSize == null) {
            this._adjustSize = new Size();
            this._adjustSize.x = this.windowSize.width * this.screenAdjustScale.width;
            this._adjustSize.y = this.windowSize.height * this.screenAdjustScale.height;
        }

        return this._adjustSize;
    }

    /**设备的屏幕比例 */
    static get screenAspectRatio() {
        return this.windowSize.width / this.windowSize.height;
    }
}

export enum TechnologyType {
    PlanetWarning, //星球预警
    EarthCannon, //地球大炮
    Shield, //护盾
}

/**科技种类 */
export class TechnologyData {
    name: string;
    cost: number;
    iconPath: string;
    des: string;
    levelMax: number;

    static TechnologyMap: Map<TechnologyType, TechnologyData> = new Map([
        [TechnologyType.PlanetWarning, {
            name: '行星预警',
            cost: 100,
            iconPath: 'texture/unit/Radar/spriteFrame',
            des: '可以预警行星距离',
            levelMax: 1
        }],
        [TechnologyType.EarthCannon, {
            name: '地球大炮',
            cost: 100,
            iconPath: 'texture/unit/anti-aircraft-gun/spriteFrame',
            des: '在星球上建造可打击深空的巨炮科技',
            levelMax: 10
        }],
        [TechnologyType.Shield, {
            name: '护盾',
            cost: 200,
            iconPath: 'texture/btn/shield/spriteFrame',
            des: '增加护盾并分析出敌人的护盾和血条（电力值）',
            levelMax: 10
        }],
    ]);
}

/**遗物种类 */
export enum RelicType {
    DysonTrackPlanA = 1, //戴森球计划A （同步轨道捕获，优先外围）
    DysonTrackPlanB, //戴森球计划B （同步轨道捕获，优先内围）
    LightParticleStrike, //光粒打击
}

/**遗物数据 */
export class RelicData {
    name: string;
    iconPath: string;
    des: string;

    static RelicMap: Map<RelicType, RelicData> = new Map([
        [RelicType.DysonTrackPlanA, {
            name: '戴森球A',
            iconPath: 'texture/unit/orbit/spriteFrame',
            des: '高等文明遗物，卫星强制捕获技术，外圈优先.'
        }],
        [RelicType.DysonTrackPlanB, {
            name: '戴森球B',
            iconPath: 'texture/unit/orbit/spriteFrame',
            des: '高等文明遗物，卫星强制捕获技术，内圈优先.'
        }],
        [RelicType.LightParticleStrike, {
            name: '光粒打击',
            iconPath: 'texture/unit/laser-blast/spriteFrame',
            des: '高等文明遗物，使用光粒打击目标.'
        }],
    ]);
}


/**技能种类 */
export enum SkillType {
    LightParticleStrike = 1, //光粒打击
}

/**技能数据 */
export class SkillData {
    name: string;
    iconPath: string;
    des: string;
    coolTime: number;
    data: number;

    static SkillMap: Map<SkillType, SkillData> = new Map([
        [SkillType.LightParticleStrike, {
            name: '光粒打击',
            iconPath: 'texture/unit/laser-blast/spriteFrame',
            des: '高级科技，可击毁星球！',
            coolTime: 30,
            data: 10,
        }],
    ]);
}

/**掉落物种类 */
export enum LootType {
    Mine, //矿场资源
    Electric, //电力资源
    Shield, //护盾值
    Technology, //科技资源
    Relic //遗物
}

/**掉落物种类 */
export class LootData {
    name: string;
    iconPath: string;
    des: string;

    static LootMap: Map<LootType, LootData> = new Map([
        [LootType.Mine, { name: '矿石资源', iconPath: 'texture/ziyuan_icon/spriteFrame', des: '用于制造单位' }],
        [LootType.Electric, { name: '电力', iconPath: 'texture/elec_icon/spriteFrame', des: '用于维持文明活动' }],
        [LootType.Shield, { name: '护盾', iconPath: 'texture/btn/shield/spriteFrame', des: '护盾' }],
        [LootType.Technology, { name: '科技点', iconPath: 'texture/reactor/spriteFrame', des: '可以用来解锁科技' }],
        [LootType.Relic, { name: '遗物', iconPath: 'texture/unit/cube/spriteFrame', des: '高等文明的产物' }]
    ]);
}

export enum UnitType {
    Base,
    /**掉落物 */
    Loot = 1,
    /**子弹 */
    Bullet = 10,
    /**基础攻击舰 */
    UnitAssault = 100,
    /**2级攻击舰 */
    UnitAssault_2 = 101,
    /**资源作业飞船 */
    UnitMining = 110,
    /**预警机 */
    UnitAwacs = 115,
    /**飞船类 */
    UnitSpacecra = 170,
    /**小行星 */
    UnitAsteroid = 180,
    /**行星 */
    UnitPlanet = 200,
    /**恒星 */
    UnitSun = 300,

    /**主要天体 */
    UnitCommonStar = 450,
    /**星系支点 */
    UnitGalaxy = 500,
}

/**单位描述 */
export class UnitMsg {
    name: string;
    iconPath: string;
    des: string;

    static msgMap: Map<UnitType, UnitMsg> = new Map([
        [UnitType.UnitMining, { name: '采矿飞船', iconPath: 'texture/unit/unit_mining/spriteFrame', des: '采矿飞船：会自动采集附近的小行星' }],
        [UnitType.UnitAssault, { name: '攻击舰', iconPath: 'texture/unit/unit_assault/spriteFrame', des: '攻击舰：会进攻附近的敌人' }],
        [UnitType.UnitAssault_2, { name: '2级攻击舰', iconPath: 'texture/unit/unit_assault_2/spriteFrame', des: '2级攻击舰：发射电磁炮攻击敌人' }],
        [UnitType.UnitAwacs, { name: '预警机', iconPath: 'texture/unit/unit_awacs/spriteFrame', des: '2级攻击舰：发射电磁炮攻击敌人' }],
        [UnitType.UnitAsteroid, { name: '小行星', iconPath: '', des: '小行星：有各种稀有资源可被采集' }],
        [UnitType.UnitPlanet, { name: '行星', iconPath: '', des: '行星：有一定的可能孕育生命' }],
        [UnitType.UnitSun, { name: '恒星', iconPath: '', des: '恒星：恒星的情绪不稳定，建议离得远远的' }],
        [UnitType.UnitGalaxy, { name: '巨引源', iconPath: '', des: '巨引源：星系中心，不要尝试靠近，其强大的引力难以逃逸！' }],
    ]);
}

export class PlayerData {
    /**等级 */
    level: number = 1;
    /**难度 */
    difficulty: number = 1;
    /**科技点 */
    technologyPoint: number = 0;
    /**科技 */
    technologyProduct: Map<TechnologyType, number> = new Map([]);
    /**遗物 */
    relics: Map<RelicType, number> = new Map([]);
    /**技能 */
    skills: Map<SkillType, { lv: number, readyTime: number, maxCount: number }> = new Map([]);
}

export interface GuideTipData {
    message: string;
    target: Node;
    offset?: Vec3;
    GameLayer?: boolean;
    lifeTime?: number;
    animInterval?: number;
    fontSize?: number;
    GuideLineSize?: number;
    GuideLineColor?: Color;

    lifeCondition?: () => boolean;
}
